program example_leapfrog

    use seakeeping_module, only: leapfrog_type, wp => sk_real_kind
    implicit none

    real(wp) :: x(1) = 0, v(1) = 0, a(1), t = 0.0_wp ! 初始值
    real(wp) :: h = 0.01_wp ! 时间步长
    type(leapfrog_type) :: leapfrog

    call leapfrog%integrate(func, t, x, v, a, h, 1)
    call leapfrog%step(t, x, v, a, h, 100, 1)

    print "(*(8X,A8))", "t", "x", "v", "a"
    print "(*(F16.10))", t, x, leapfrog%v, a ! 时间积分结果
    print "(A16,1X,ES15.3)", "Error:", x + 5.0674995205523885_wp

contains

    !> 有阻尼的落体运动
    subroutine func(t, x, v, a)
        real(wp), intent(in) :: x(:), v(:), t
        real(wp), intent(out) :: a(:)

        a = -9.8_wp + 0.1_wp*v

    end subroutine func

end program example_leapfrog
!               t               x               v               a
!    0.9999993443   -5.0674791336  -10.3066883087  -10.8306694031
!          Error:       2.050E-05
